'''
Descripttion: 
version: 
Author: jinqian
Date: 2022-05-02 10:51:03
LastEditors: jinqian
LastEditTime: 2022-05-02 17:05:28
'''

import app.controller.DockerSwarmCtl
from fastapi import APIRouter
from fastapi.encoders import jsonable_encoder
from fastapi.responses import JSONResponse
from pydantic import BaseModel

from app.utils.response import BaseRes


dockerRouter = APIRouter()


class ContainerIn(BaseModel):
    ContainerName: str
    ContainerID: str


class ImageIn(BaseModel):
    ImageName: str
    tag: str
    targetHost: str
    ContainerName: str


class node(BaseModel):
    id: str
    Hostname: str
    CreatedAt: str
    UpdatedAt: str
    Status: str
    Addr: str


class NodeOut(BaseModel):
    Nodenum: int
    Nodelist: list


class service(BaseModel):
    mainNode: str
    size: int
    mainMemory: int
    slaveMemory: int
    id: str
    servicename: str
    time: str


class ServicesOut(BaseModel):
    Servicesnum: int
    Serviceslist: list


class Tasksout(BaseModel):
    Tasknum: int
    Taskinfo: list


@dockerRouter.post('/docker/add')
async def dockeradd():
    pass


@dockerRouter.post('/docker/delete')
async def dockerdel():
    pass


@dockerRouter.post('/docker/modify')
async def dockermod():
    pass


@dockerRouter.post('/docker/search')
async def dockersearch():
    pass


@dockerRouter.post('/docker/list/service')
async def dockerlistservice():
    ServiceList = app.controller.DockerSwarmCtl.GetServiceList()
    return JSONResponse(content=jsonable_encoder(BaseRes(data=ServicesOut(Servicesnum=len(ServiceList), Serviceslist=ServiceList))))


@dockerRouter.get('/docker/list/node')
async def dockerlistnode():
    NodeList = app.controller.DockerSwarmCtl.GetNodeList()
    return JSONResponse(content=jsonable_encoder(BaseRes(data=NodeOut(Nodenum=len(NodeList), Nodelist=NodeList))))


@dockerRouter.post('/docker/list/task')
async def dockerlisttask():
    TaskList = app.controller.DockerSwarmCtl.GetTaskList()
    return JSONResponse(content=jsonable_encoder(BaseRes(data=Tasksout(Tasknum=len(TaskList), Taskinfo=TaskList))))
